package org.xurui.bsj.protocol.msg;

import java.util.HashMap;
import java.util.Map;

public class BsjMessage {
    private Header header;//起始标识符号
    private Map<String,Object> body;//报文体
    private String endMark;//结束标示符号
    private String tempBody;//临时待解报文体
    private String tempReplyBody;//临时回复消息
    private boolean withOutRelayToDevice;//设备上报消息是否立即回复
    public BsjMessage(){
        this.header = new BsjMessage.Header();
        this.body = new HashMap<>();
        this.endMark = "]";
    }

    public Header getHeader() {
        return header;
    }

    public void setHeader(Header header) {
        this.header = header;
    }

    public Map<String, Object> getBody() {
        return body;
    }

    public void setBody(Map<String, Object> body) {
        this.body = body;
    }

    public String getEndMark() {
        return endMark;
    }

    public void setEndMark(String endMark) {
        this.endMark = endMark;
    }

    public boolean isWithOutRelayToDevice() {
        return withOutRelayToDevice;
    }

    public void setWithOutRelayToDevice(boolean withOutRelayToDevice) {
        this.withOutRelayToDevice = withOutRelayToDevice;
    }

    public String getTempBody() {
        return tempBody;
    }

    public void setTempBody(String tempBody) {
        this.tempBody = tempBody;
    }

    public String getTempReplyBody() {
        return tempReplyBody;
    }

    public void setTempReplyBody(String tempReplyBody) {
        this.tempReplyBody = tempReplyBody;
    }

    public class Header{
        private String beginMark;//起始标识符
        private String deviceNo;//设备号
        private String iccid;//sim卡iccid
        private String orderNo;//交易流水号 时间格式+4 位循环数
        private String cmd;//接口唯一标识
        /**
         * 标识通信方向，取值如下:
         * 1.下发请求
         * 2.下发响应
         * 3.上报请求
         * 4.上报响应
         * 说明：平台下发请求标示 1，则终 端响应标示为 2，终端上报接口标 示为 3，平台响应标示为 4
         */
        private Integer type;//报文类型
        /**
         * 设备或者服务器时间，时间格式 为：yyyyMMddHHmmss
         */
        private String msgTime;//设备或者服务器时间
        private Integer length;//报文长度

        public String getBeginMark() {
            return beginMark;
        }

        public void setBeginMark(String beginMark) {
            this.beginMark = beginMark;
        }

        public String getDeviceNo() {
            return deviceNo;
        }

        public void setDeviceNo(String deviceNo) {
            this.deviceNo = deviceNo;
        }

        public String getIccid() {
            return iccid;
        }

        public void setIccid(String iccid) {
            this.iccid = iccid;
        }

        public String getOrderNo() {
            return orderNo;
        }

        public void setOrderNo(String orderNo) {
            this.orderNo = orderNo;
        }

        public String getCmd() {
            return cmd;
        }

        public void setCmd(String cmd) {
            this.cmd = cmd;
        }

        public Integer getType() {
            return type;
        }

        public void setType(Integer type) {
            this.type = type;
        }

        public String getMsgTime() {
            return msgTime;
        }

        public void setMsgTime(String msgTime) {
            this.msgTime = msgTime;
        }

        public Integer getLength() {
            return length;
        }

        public void setLength(Integer length) {
            this.length = length;
        }

        public java.util.Map<String, Object> toMap() {
            final java.util.Map<String, Object> map = new java.util.HashMap<>();
            map.put("beginMark", this.beginMark);
            map.put("deviceNo", this.deviceNo);
            map.put("iccid", this.iccid);
            map.put("orderNo", this.orderNo);
            map.put("cmd", this.cmd);
            map.put("type", this.type);
            map.put("msgTime", this.msgTime);
            map.put("length", this.length);
            return map;
        }

        @Override
        public String toString() {
            return "Header{" +
                "beginMark='" + beginMark + '\'' +
                ", deviceNo='" + deviceNo + '\'' +
                ", iccid='" + iccid + '\'' +
                ", orderNo='" + orderNo + '\'' +
                ", cmd='" + cmd + '\'' +
                ", type=" + type +
                ", msgTime='" + msgTime + '\'' +
                ", length=" + length +
                '}';
        }
    }

    @Override
    public String toString() {
        return "BsjMessage{" +
            "header=" + header +
            ", body=" + body +
            ", endMark='" + endMark + '\'' +
            ", tempBody='" + tempBody + '\'' +
            ", tempReplyBody='" + tempReplyBody + '\'' +
            '}';
    }
}
